package net.zoneland.zrdp.web;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.branchitech.spi.HttpInvokerProvider;
import com.branchitech.utils.SystemHelper;
import com.google.common.collect.Maps;

@RestController
@RequestMapping("/test/")
public class HttpClientTestController {

    @RequestMapping("search-on-web")
    @ResponseBody
    public String searchOnBaidu(final String q, final HttpServletResponse response) {
        final Map<String, String> params = Maps.newHashMap();
        params.put("q", q);
        final HttpInvokerProvider httpInvokerProvider = SystemHelper.getHttpInvokerProvider();
        final String result = httpInvokerProvider.doGet("https://cn.bing.com/search", params, null);
        response.setContentType("text/plain;charset=UTF-8");
        return result.replaceFirst("<head>", "<head><base href=\"https://cn.bing.com/\" />");
    }
}
